package com.example.controller;

import cn.hutool.crypto.digest.DigestUtil;
import com.example.config.QiniuConfig;
import com.example.event.MyEvent;
import com.example.rvo.ResultVO;
import com.example.service.TestRetryService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(produces = "application/json;charset=utf-8")
public class FirstController {

    @Value("${person.username}")
    private String name;

    @Resource
    private QiniuConfig qiniuConfig;
    /**
     * 监听需要注入对应ApplicationContext
     */
    @Resource
    private ApplicationContext applicationContext;

    @Resource
    private TestRetryService testRetryService;


    @RequestMapping("/hello")
    public String hello(){
        System.out.println("事件开始发布消息："+System.currentTimeMillis());
        //发布时间实现对应的监听内容的操作
        applicationContext.publishEvent(new MyEvent(this,"你好啊"));
        return "success";
    }

    @GetMapping(value="/first")
    public String first(){
        return DigestUtil.md5Hex("123456");
    }


    @GetMapping("/getName")
    public String getName(@RequestParam("name") String name){
        return name;
    }

    @GetMapping("/getaksk")
    public String getaksk(){
        return qiniuConfig.getAk() + ":"+ qiniuConfig.getSk();
    }

    @GetMapping("/retry")
    public int retry(Integer code) throws Exception {
            return testRetryService.test(code);
    }

    @GetMapping("/getddd")
    public String getsssddd(){
        return "猎杀时刻";
    }
    @GetMapping("/getaaddd")
    public String getddd(){
        return "暗杀时刻";
    }

    @GetMapping("/getcccccccccccccc")
    public String getcccccccccccccc(){
        return "ccccccccccccc";
    }


    @GetMapping("/test")
        public ResultVO test(){
        String name  = null;
        System.out.println("aaaaa");
        return ResultVO.success("200","成功",name);
        }
}
